package com.nacosconsumer.prac.controller;

import java.util.List;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author H
 * @Description
 * @date 2023-05-30 11:41
 */

@RestController
public class NacosController {

    @Resource
    private RestTemplate restTemplate;
    @Value("${server-url.nacos-provider}")
    private String serverUrl;

    @GetMapping("/t/{id}")
    public ResponseEntity<String> test(@PathVariable("id") Integer id) {
        return restTemplate.getForEntity(serverUrl + "/nacos/echo/" + id, String.class);
    }

    @GetMapping("/lb")
    public ResponseEntity<String> test2() {
        return restTemplate.getForEntity(serverUrl + "/nacos/echo/" + 1000, String.class);
    }

    @GetMapping("/discovery")
    public List<String> discovery() {
        return restTemplate.getForObject(serverUrl + "/nacos/discovery", List.class);
    }

}
